#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QMenu>
#include <QAction>
#include <QStatusBar>
#include <QLabel>
#include <QSplitter>
#include <QToolBox>
#include <QGroupBox>
#include <QToolButton>
#include <QScrollArea>
#include <QGridLayout>
#include <QFrame>
#include <QHash>
#include <QTcpSocket>
#include <QSystemTrayIcon>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <QPushButton>
#include <phonon/VideoPlayer>
#include <QMovie>

class DataCenter;
class ClientCenter;
class ClientGroupCenter;
class ClientBriefInfoPanel;
class TimeLabel;
class GroupListWidget;
class RegisterNotifierIcon;
class RegisterRequest;
class UnnormalState;
class UnnormalStateNotifierIcon;
class CameraMoniter;
class LoginDialog;
class WindowFactory;
class ConfigureDialog;

class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	MainWindow(QWidget *parent = 0);
	~MainWindow();
private slots:
	void exit();
	void about();
	void onLoginSuccess();
	void showConfigureDialog();
private:
	void createFunction();
	void createChildWindow();
	void createMenus();
	void createStatusBar();
	void createGroups();
	void createClients();
	void setupWidgets();
	void startServer();
	void createCameraMoniter();
	void createMiddleFunctionMenu();

	void showLoginDialog();
private slots:
	void onClientListChanged();
	void onAddGroupAction();
	void onAddClientAction();
	void updateGroupPanelList(int opType, int opId);
	void onServerNetworkError(int errorCode);
	void onPlayPlanAction();
	void onVolumePlayAction();
	void onNetworkStatusLogAction();
	void onFileTransferLogAction();
	void onPlayListLogAction();
	void onUnnormalStatisticAction();
	void onNewContractAction();
	void onQueryContractAction();
	void onRealTimeVideoPlayAction();
	void onSplitModeSetAction();
	void onParametersAction();
	void onTrayIconActived(QSystemTrayIcon::ActivationReason activeReason);
	void onClientOnlineChanged(bool isOnline);
	void onNewRegisterRequest(RegisterRequest* registerRequest);
	void onMapManageAction();
	void onShowSendFileAction();
	void onShowUnnormalAction();
	void onNewUnnormalState(UnnormalState* state);
	void onCurrentPlayAction();
	void onCameraMoniterAction();
	void onSubShowAction();
	void onHelpAction();

	void onGroupInfoAction();
	void onDeviceSwitchCtrl();
	void onTimingSwitchCtrl();

	void onClientInfoButton();
	void onProgramManagementButton();
	void onSecurityButton();
	void onContractButton();
	void onLogButton();
	void hideFunctionMenu();

	void showGroupView(int clientGroupId);
	void changeButtonColor(QPushButton *pushButton);

	void playAd();

protected:
	void closeEvent(QCloseEvent *);
private:
	QVBoxLayout* m_LeftLayout;
	QFrame* m_LeftFrame;

	QGroupBox* m_TitlePic;
//	QLabel* m_WarnLabel;
//	QMovie* m_WarnMovie;

//	QLabel* m_ClientLabel;
//	QMovie* m_ClientMovie;

	UnnormalStateNotifierIcon *m_BigUnnormalStateNotifierIcon;
	RegisterNotifierIcon *m_BigRegisterNotifierIcon;


	QFrame *m_MiddleFrame;
	QHBoxLayout *m_MiddleLayout;
	QPushButton *m_ClientInfoButton;
	QPushButton *m_ProgramManagementButton;
	QPushButton *m_SecurityButton;
	QPushButton *m_ContractButton;
	QPushButton *m_LogButton;

	QGroupBox *groupBox1;
	QGroupBox *groupBox2;
	QGroupBox *groupBox3;
	QGroupBox *groupBox4;
	QGroupBox *groupBox5;
	QGroupBox *groupBox6;
	QVBoxLayout *layout1;
	QVBoxLayout *layout2;
	QVBoxLayout *layout3;
	QVBoxLayout *layout4;
	QVBoxLayout *layout5;
	QVBoxLayout *layout6;
	Phonon::VideoPlayer *m_ADVideo;
	QString fileName;

	QToolButton *m_MapConfiguration;
	QToolButton *m_GroupInfo;

	QToolButton *m_ViewPlayingFile;
	QToolButton *m_PlayPlan;
	QToolButton *m_VolumePlan;
	QToolButton *m_RealTimePlay;
	QToolButton *m_SubShow;
	QToolButton *m_SplitModSet;

	QToolButton *m_DeviceSwitchCtrl;
	QToolButton *m_TimingSwitchCtrl;
	QToolButton *m_UnnormalFeedback;
	QToolButton *m_VideoMonitor;

	QToolButton *m_NewContract;
	QToolButton *m_QueryContract;

	QToolButton *m_NetworkLog;
	QToolButton *m_SendFileLog;
	QToolButton *m_PlayListLog;
	QToolButton *m_UnnormalStateStatistic;

	QScrollArea* m_RightArea;
	QVBoxLayout* m_RightLayout;
	QFrame* m_RightFrame;
	QVBoxLayout* m_RightWindowLayout;
	QWidget* m_WindowPoint;

	QMenu* m_FileMenu;
	QMenu* m_ViewMenu;
	//QMenu* m_ToolMenu;
	//QMenu* m_ClientMenu;
	//QMenu* m_GroupMenu;
	//QMenu* m_ProgramMenu;
	//QMenu* m_SecurityMenu;
	//QMenu* m_ContractMenu;
	QMenu* m_OptionMenu;
	//QMenu* m_LogMenu;
	//QMenu* m_MapMenu;
	QMenu* m_HelpMenu;

	QAction* m_ExitAction;

	QAction* m_ShowSendFileAction;
	QAction* m_ShowRegisterAction;
	QAction* m_ShowUnnormalAction;

	QAction* m_AddClientAction;
	QAction* m_ClientInfoAction;

	QAction* m_AddGroupAction;
	QAction* m_GroupInfoAction;

	QAction* m_CurrentPlayAction;
	QAction* m_PlayPlanAction;
	QAction* m_VolumePlayAction;
	QAction* m_RealTimePlayAction;
	QAction* m_SubShowAction;

	QAction* m_CameraMoniterAction;

	QAction* m_NewContractAction;
	QAction* m_QueryContractAction;

	QAction* m_ParametersAction;

	QAction* m_NetworkStatusLogAction;
	QAction* m_FileTransferLogAction;
	QAction* m_PlayListLogAction;
	//QAction* m_UnnormalStateStatistic;

	QAction* m_MapManageAction;

	QAction* m_HelpAction;
	QAction* m_AboutAction;

	//QLabel* m_CurrentGroup;
	QLabel* m_CurrentWindow;
	UnnormalStateNotifierIcon *m_UnnormalNotifierIcon;
	RegisterNotifierIcon *m_RegisterNotifierIcon;
	TimeLabel* m_TimeLabel;

	QSplitter* m_VSplitter;
	QSplitter* m_MainSplitter;
	QScrollArea* m_GroupScrollArea;
	GroupListWidget* m_GroupList;
	QFrame* m_ClientContainer;
	QGridLayout* m_ClientContainerLayout;
	QSystemTrayIcon *m_TrayIcon;
	ClientBriefInfoPanel* test;

private:
	//int lastGroupId;
	boost::shared_ptr<DataCenter> m_DataCenter;
	boost::shared_ptr<ClientCenter> m_ClientCenter;
	boost::shared_ptr<ClientGroupCenter> m_ClientGroupCenter;
	QMap<int, ClientBriefInfoPanel* > m_ClientBriefInfoPanelList;
	CameraMoniter* m_CameraMoniter;
	LoginDialog* m_LoginDialog;
	WindowFactory *m_WindowFactory;
	ConfigureDialog *m_ConfigureDialog;
};

#endif // MAINWINDOW_H
